import { post, get, put, deletee, postLogin, baseUrl } from "@/request/http.js";

// var baseUrl = "http://192.168.50.100:3000";
// export const baseUrl = process.env.VUE_APP_BASE_URL;
export const basUrl = baseUrl;

export function login(params = {}) {
  return postLogin(`/login`, params);
}

export function logout() {
  return post(`/logout`);
}

export function getInfo() {
  return get(`/me`);
}
export function buildMenus(params = {}) {
  return get(`/build/menus`, params);
}

//apiService

export const apiService = {
  queryEachTable: (tname, params = {}) => get(tname, params),
  putEachTable: (tname, params) => {
    return post(tableUrl[tname], params);
  },
  postEachTable: (tname, params) => {
    return post(tableUrl[tname], params);
  },

  queryTable: (params = {}) => get(`/collect/config/table`, params),
  putTable: (params = {}) => {
    return put(`/collect/config/table`, params);
  },
  deleteTable: (params, tableCode) =>
    deletee(`/collect/config/table/${tableCode}`, params),
  queryColumn: (params = {}) => get(`/collect/config/column`, params),
  putColumn: (params = {}) => {
    return put(`/collect/config/column`, params);
  },
  deleteColumn: params => deletee(`/collect/config/column`, params),
  queryRule: (params = {}) => get(`/collect/check/rule`, params),
  putRule: (params = {}) => {
    return put(`/collect/check/rule`, params);
  },
  deleteRule: params => deletee(`/collect/check/rule`, params),
  queryCheckConfig: (params = {}) => get(`/collect/check/config`, params),
  putCheckConfig: (params = {}) => {
    return put(`/collect/check/config`, params);
  },
  deleteCheckConfig: params => deletee(`/collect/check/config`, params),
  refreshCheckConfig: params => get(`/collect/check/config/refresh`, params),

  queryData: (params = {}, tableCode) =>
    get(`/collect/content/${tableCode}`, params),

  exportItem: (params = {}) => get(`/collect/packet/export`, params),
  checkItem: (params = {}, tableCode) =>
    get(`/collect/check/${tableCode}`, params),
  deleteItem: (params, tableCode) =>
    deletee(`/collect/content/${tableCode}`, params),
  updateItem: (params, tableCode) => {
    return post(`/collect/content/${tableCode}`, params);
  },
  putItem: (params = {}, tableCode) => {
    return put(`/collect/content/${tableCode}`, params);
  }
  // getById: (params) => {
  //   return get(`/api/jgxxb/${params.id}`, params);
  // },
  // all: (params = {}) => {
  //   return get(`/api/jgxxb/all`, params);
  // },
};

// sysjeptService
export const sysdeptService = {
  queryData: (params = {}) => get(`/sysdept`, params),
  postItem: (params = {}) => {
    return post(`/sysdept`, params);
  },
  deleteItem: params => post(`/sysdept/d`, params),

  getById: params => {
    return get(`/sysdept/${params.id}`, params);
  },
  all: (params = {}) => {
    return get(`/sysdept/all`, params);
  },
  tree: (params = {}) => get(`/sysdept/tree`, params)
};

// sysjobService
export const sysjobService = {
  queryData: (params = {}) => get(`/sysjob`, params),
  postItem: (params = {}) => {
    return post(`/sysjob`, params);
  },
  deleteItem: params => post(`/sysjob/d`, params),

  getById: params => {
    return get(`/sysjob/${params.id}`, params);
  },
  all: (params = {}) => {
    return get(`/sysjob/all`, params);
  }
};

// sysdictService
export const sysdictService = {
  queryData: (params = {}) => get(`/sysdict`, params),
  postItem: (params = {}) => {
    return post(`/sysdict`, params);
  },
  deleteItem: params => post(`/sysdict/d`, params),

  getById: params => {
    return get(`/sysdict/${params.id}`, params);
  },
  all: (params = {}) => {
    return get(`/sysdict/all`, params);
  }
};

// sysdictdetailService
export const sysdictdetailService = {
  queryData: (params = {}) => get(`/sysdictdetail`, params),
  postItem: (params = {}) => {
    return post(`/sysdictdetail`, params);
  },
  deleteItem: params => post(`/sysdictdetail/d`, params),

  getById: params => {
    return get(`/sysdictdetail/${params.id}`, params);
  },
  all: (params = {}) => {
    return get(`/sysdictdetail/all`, params);
  }
};

// sysuserService
export const sysuserService = {
  queryData: (params = {}) => get(`/sysuser`, params),
  postItem: (params = {}) => {
    return post(`/sysuser`, params);
  },
  passReset: (params = {}) => {
    return post(`/sysuser/pass/reset/${params.oid}`, params);
  },
  deleteItem: params => post(`/sysuser/d`, params),

  getById: params => {
    return get(`/sysuser/${params.id}`, params);
  },
  all: (params = {}) => {
    return get(`/sysuser/all`, params);
  }
};

// sysmenuService
export const sysmenuService = {
  queryData: (params = {}) => get(`/sysmenu`, params),
  postItem: (params = {}) => {
    return post(`/sysmenu`, params);
  },
  deleteItem: params => post(`/sysmenu/d`, params),

  getById: params => {
    return get(`/sysmenu/${params.id}`, params);
  },
  tree: (params = {}) => {
    return get(`/sysmenu/tree`, params);
  },
  menuselect: (params = {}) => get(`/sysmenu/menuselect`, params)
};

// sysroleService
export const sysroleService = {
  queryData: (params = {}) => get(`/sysrole`, params),
  postItem: (params = {}) => {
    return post(`/sysrole`, params);
  },
  deleteItem: params => post(`/sysrole/d`, params),

  getById: params => {
    return get(`/sysrole/${params.id}`, params);
  },
  getMenusByRole: roleId => {
    return get(`/sysrole/menus/${roleId}`);
  },
  all: (params = {}) => {
    return get(`/sysrole/all`, params);
  },
  saveRoleMenus: (params = {}) => {
    return post(`/sysrole/${params.roleId}/menus`, params);
  }
};
